package action;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import bean.Department;
import bean.Employee;
import bean.Plan;
import bean.Report;
import biz.DepartmentBiz;
import biz.EmployeeBiz;
import biz.PlanBiz;
import biz.ReportBiz;
import biz.impl.DepartmentBizImpl;
import biz.impl.EmployeeBizImpl;
import biz.impl.PlanBizImpl;
import biz.impl.ReportBizImpl;

public class ReportupdateAction extends HttpServlet {
	public void doPost(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		String page = "report_list.jsp";
		request.setCharacterEncoding("gbk");
		int rid=Integer.parseInt(request.getParameter("rid"));
		String content = request.getParameter("content");
		String complete = request.getParameter("complete");
		String completeState = request.getParameter("completeState");
		String completeTime = request.getParameter("completeTime");
		int depId=Integer.parseInt(request.getParameter("depId"));
		int eid=Integer.parseInt(request.getParameter("eid"));
		int pid=Integer.parseInt(request.getParameter("pid"));
		HttpSession session=request.getSession();
		Employee employee=(Employee) session.getAttribute("login");
		ReportBiz rb=new ReportBizImpl();
		DepartmentBiz db=new DepartmentBizImpl();
		EmployeeBiz empBiz=new EmployeeBizImpl();
		PlanBiz planBiz=new PlanBizImpl();
		Report report=rb.getReportByrid(rid);
		report.setComplete(complete);
		report.setCompletestate(completeState);
		report.setCompletetime(completeTime);
		report.setContent(content);
		Department department=db.getDepartmentBydepId(depId);
		report.setDepartment(department);
		Employee emp=empBiz.getEmployeeByeid(eid);
		report.setEmployee(employee);
		Plan plan=planBiz.getPlanBypid(pid);
		report.setPlan(plan);
		boolean success=rb.update(report);
		if(success==true){
			response.sendRedirect("ReportsearchAction");
		}else{
			response.sendRedirect("update_report.jsp");
		}
		
		
	}

	public void doGet(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {

	}
}
